﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LaughingDog.GameObjects;
using FarseerGames.FarseerPhysics.Factories;
using LaughingDog.Managers;

namespace LaughingDog.Components
{
    /// <summary>
    /// Creates an instance of a EllipseCollider component.
    /// </summary>
    /// <param name="gameObject">The GameObject this Component should be attached to.</param>
    public class EllipseCollider : Collider
    {        
        private const Int32 DEFAULT_NUMBER_OF_EDGES = 10;

        /// <summary>
        /// Creates an instance of an EllipseCollider component.
        /// </summary>
        /// <param name="gameObject">The GameObject this Component should be attached to.</param>
        public EllipseCollider(GameObject gameObject)
            : base(gameObject)
        {
            // If no RigidBody component is attached then attach a basic one without adding it to the physics simulator just so we can use Collider features.
            if (GameObject.RigidBody == null)
                GameObject.AddComponent<RigidBody>();

            mGeom = GeomFactory.Instance.CreateEllipseGeom(PhysicsManager.Instance.Simulator, GameObject.RigidBody.Body, GameObject.Transform.ScaledSize.X / 2, GameObject.Transform.ScaledSize.Y / 2, DEFAULT_NUMBER_OF_EDGES, 1);
            mGeom.OnCollision += Collision;
            mGeom.OnSeparation += Seperation;

            mGeomColliderPairs.Add(mGeom, this);

            IsTrigger = false;
        }
    }
}
